<template>
  <div id="frontBanner">
<!--    统计轮播 start-->
    <el-carousel :interval="4000" type="card" height="400px" v-if="showstatics">
      <el-carousel-item v-for="item in echartsArr" :key="item.id  ">
        <div style="height: 100px;line-height: 100px">
          <h3>{{item.title}}</h3>
        </div>
        <div class="echart" style="position: relative">
          <MyEchart v-if="requestSuccess" :id="item.id" :options="item.options" style="height: 300px;"></MyEchart>
        </div>
      </el-carousel-item>
    </el-carousel>
<!--    统计轮播 start-->
<!--    小店介绍 start-->
    <el-carousel :interval="4000" type="card" height="400px" v-else>
      <el-carousel-item>
        <div style="height: 100px;line-height: 100px">
          <h3>我们的小店</h3>
        </div>
        <div>
<!--          <p>-->
<!--            第三组的餐饮小店成立时间不到两周,这里特别感谢以下工作者的辛苦劳动使得我们小店终于呈现在大家面前-->
<!--          </p>-->
          <h3>特别鸣谢: 前端组</h3>
          <ul>
            <li>组长: 李安君 负责个人信息页面</li>
            <li>组员: 袁官锐 负责后台工作统筹、公共封装、个人任务</li>
            <li>组员: 李亚平 负责后台菜品管理、基本信息管理</li>
            <li>组员: 何嘉伟 负责统计相关任务</li>
            <li>组员: 陈凤 负责前台工作统筹、个人任务</li>
          </ul>
          <h3>特别鸣谢: 后端组</h3>
          <ul>
            <li>组长: 刘道平 负责前台接口以及统筹</li>
            <li>组员: 雷江 负责前台接口</li>
            <li>组员: 李建国 负责后台财务分析、库存管理</li>
            <li>组员: 周银涛 负责菜品管理和基础信息管理</li>
            <li>组员: 李小平 负责后台运营管理</li>
          </ul>
        </div>
      </el-carousel-item>
      <el-carousel-item>
        <div style="height: 100px;line-height: 100px">
          <h3>店内推广</h3>
        </div>
        <div>
          <img :src="banner1" alt="">
        </div>
      </el-carousel-item>
      <el-carousel-item>
        <div style="height: 100px;line-height: 100px">
          <h3>店内环境</h3>
        </div>
        <div>
          <img :src="banner2" alt="">
        </div>
      </el-carousel-item>
    </el-carousel>
<!--    小店介绍 send-->

  </div>
</template>

<script>
  import MyEchart from './MyEchart'
  import banner1 from '../../../assets/banners/banner1.jpg'
  import banner2 from '../../../assets/banners/banner2.jpg'
  import {mapActions} from 'vuex'
  export default {
    name: "FrontBanner",
    props:['showstatics'],
    components: {
      MyEchart
    },
    data(){
      return {
        requestSuccess: false,
        showWhich: 'statistics1',
        echartsArr:[
          {
            id: 'pie1',
            title: '就餐高峰时段',
            options: {
              backgroundColor: '#fff',
              xAxis: {
                type: 'category',
                data: []
              },
              yAxis: {
                type: 'value'
              },
              series: [{
                data: [],
                type: 'bar',
                showBackground: true,
                backgroundStyle: {
                  color: 'rgba(220, 220, 220, 0.8)'
                }
              }]
            }
          },
          {
            id: 'pie2',
            title: '酒水饮料受欢迎排行',
            options: {
              backgroundColor: '#2c343c',
              title: {
                text: '酒水饮料受欢迎排行',
                left: 'center',
                top: 20,
                textStyle: {
                  color: '#000'
                }
              },

              tooltip: {
                trigger: 'item',
                formatter: '{a} <br/>{b} : {c} ({d}%)'
              },

              visualMap: {
                show: false,
                min: 80,
                max: 600,
                inRange: {
                  colorLightness: [0, 1]
                }
              },
              series: [
                {
                  name: '访问来源',
                  type: 'pie',
                  radius: '55%',
                  center: ['50%', '50%'],
                  data: [
                    {value: 335, name: '直接访问'},
                    {value: 310, name: '邮件营销'},
                    {value: 274, name: '联盟广告'},
                    {value: 235, name: '视频广告'},
                    {value: 400, name: '搜索引擎'}
                  ].sort(function (a, b) {
                    return a.value - b.value;
                  }),
                  roseType: 'radius',
                  label: {
                    color: 'rgba(255, 255, 255, 0.3)'
                  },
                  labelLine: {
                    lineStyle: {
                      color: '#f00'
                    },
                    smooth: 0.2,
                    length: 10,
                    length2: 20
                  },
                  itemStyle: {
                    color: '#c23531',
                    shadowBlur: 200,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                  },

                  animationType: 'scale',
                  animationEasing: 'elasticOut',
                  animationDelay: function (idx) {
                    return Math.random() * 200;
                  }
                }
              ]
            }
          },
          {
            id: 'dishesTop',
            title: '美味佳肴榜',
            options: {
              backgroundColor: '#2c343c',
              title: {
                text: '销量最好的菜品有你喜欢的吗',
                left: 'center',
                top: 20,
                textStyle: {
                  color: '#000'
                }
              },

              tooltip: {
                trigger: 'item',
                formatter: '{a} <br/>{b} : {c} ({d}%)'
              },

              visualMap: {
                show: false,
                min: 80,
                max: 600,
                inRange: {
                  colorLightness: [0, 1]
                }
              },
              series: [
                {
                  name: '占据榜单菜品',
                  type: 'pie',
                  radius: '55%',
                  center: ['50%', '50%'],
                  data: [],
                  roseType: 'radius',
                  label: {
                    color: '#000'
                  },
                  labelLine: {
                    lineStyle: {
                      color: '#f00'
                    },
                    smooth: 0.2,
                    length: 10,
                    length2: 20
                  },
                  itemStyle: {
                    color: '#c23531',
                    shadowBlur: 200,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                  },

                  animationType: 'scale',
                  animationEasing: 'elasticOut',
                  animationDelay: function (idx) {
                    return Math.random() * 200;
                  }
                }
              ]
            }
          }
        ],
        shopDesc:{
        
        },
        banner1: banner1,
        banner2: banner2
      }
    },
    methods: {
      ...mapActions('frontHome/',['getTopDishes'])
    },
    created() {
      this.getTopDishes().then(statics => {
        console.log(statics)
        // 菜单排行
        let dishesData = []
        statics.dishesTop3.forEach(item => {
          let oneItem = {
            value: item.number,
            name: item.dishesMainId
          }
          dishesData.push(oneItem)
        })
        this.echartsArr[2].options.series[0].data = dishesData.sort(function (a, b) {
          return a.value - b.value;
        })

        // 翻桌排行
        let seatData = []
        statics.timePeriod.forEach(item => {
          this.echartsArr[0].options.xAxis.data.push(item.time)
          this.echartsArr[0].options.series[0].data.push(item.count)
        })

        // 菜单排行
        let drinkData = []
        statics.drinkTop3.forEach(item => {
          let oneItem = {
            value: item.number,
            name: item.dishesMainId
          }
          drinkData.push(oneItem)
        })
        this.echartsArr[1].options.series[0].data = drinkData.sort(function (a, b) {
          return a.value - b.value;
        })
        this.requestSuccess = true
      })
    }
  }
</script>

<style lang="less" scoped>
#frontBanner {
  h3 {
    text-align: center;
    color: #ACE0F8;
  }
  li,p{
    text-align: center;
  }
  li{
    color: #282828;
  }
  height: 100%;
  .el-carousel__item h3 {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    margin: 0;
  }
  
  .el-carousel__item {
    background-color: #ACE0F8;
  }
  
}
</style>
